#include <iostream>
#include <memory>

// 策略接口
class DataProcessingStrategy {
public:
    virtual void process() = 0; 				// 策略接口中定义的处理数据的纯虚函数
    virtual ~DataProcessingStrategy() {} 		// 虚析构函数，保证资源被正确释放
};

// 具体策略类：高性能GPU处理
class HighPerformanceGPUProcessing : public DataProcessingStrategy {
public:
    void process() override {
        std::cout << "Processing data with high-performance GPU." << std::endl;
    }
};

// 具体策略类：标准CPU处理
class StandardCPUProcessing : public DataProcessingStrategy {
public:
    void process() override {
        std::cout << "Processing data with standard CPU." << std::endl;
    }
};

// 客户端代码
class DataProcessor {
private:
    std::unique_ptr<DataProcessingStrategy> strategy;

public:
    DataProcessor(std::unique_ptr<DataProcessingStrategy> strategy) : strategy(std::move(strategy)) {}

    void setStrategy(std::unique_ptr<DataProcessingStrategy> newStrategy) {
        strategy = std::move(newStrategy);
    }

    void processData() {
        strategy->process(); 				// 使用当前策略处理数据
    }
};

int main() {
    // 根据运行时的配置或环境选择策略
    std::unique_ptr<DataProcessingStrategy> strategy;
    
    if (/* 条件：高性能GPU可用*/1) {
        strategy = std::make_unique<HighPerformanceGPUProcessing>();
    } else {
        strategy = std::make_unique<StandardCPUProcessing>();
    }

    DataProcessor processor(std::move(strategy));
    processor.processData(); 				// 处理数据

    // 动态改变策略
    processor.setStrategy(std::make_unique<StandardCPUProcessing>());
    processor.processData(); 				// 重新处理数据

    return 0;
}